Mercredi 7 Octobre 2020 (MeetUp)
Les scripts :
“standards” dans un fichier .R
“Rmarkdown” dans un fichier .Rmd
Les “données” :
un objet dans un .rds
une liste d’objet dans un .Rdata
RStudio :
https://www.rstudio.com/products/rstudio/download/#download
Emacs + ESS :
https://ess.r-project.org
vim + Nvim-R :
https://medium.com/free-code-camp/turning-vim-into-an-r-ide-cd9602e8c217
Visual Studio + RTVS :
https://docs.microsoft.com/en-us/visualstudio/rtvs
Lorsque vous quittez :
Lorsque vous démarrez :
* Le workspace est automatiquement sauvegardé/chargé via un fichier nommé .Rdata (là où s’execute ).
.bash_profilerm(list = ls())?If the first line of your R script is
rm(list = ls())I will come into your office and SET YOUR COMPUTER ON FIRE 🔥.
— Jenny Bryan
rm(list = ls()) ?Réinitialiser la session en cours
Réinitialiser les options()
→ options(stringsAsFactors = FALSE)*
Réinitialiser le répertoire de travailgetwd() → setwd()
Réinitialiser les extensions attachées
*Valeur par défaut v4.0.0 (Kurt Hornik: stringsAsFactors).
rm(list = ls()) ?help(rm)
Ctrl+Dq() dans une console Ctrl+Shift+F10.Renviron & .Rprofile.Renviron & .Rprofile.Renviron - contient des variables d’environnement.Rprofile - contient du code .Renviron.Renviron - contient des variables d’environnement.Renviron.Renviron - contient des variables d’environnementR_MAX_NUM_DLLS=300 GITHUB_PAT=abc123 TZ='Etc/UTC' R_LIBS_USER=~/R/%p/%v
La variable R_PROFILE_USER permet de définir à partir de quel répertoire le .Rprofile est chargé.
R_PROFILE_USER=~/.Rprofile # Par défaut
.Rprofile.Rprofile.Rprofile ?options(width = 120))Mais, ATTENTION !
.Rprofile et reproductibilitéCe qui figure dans le fichier .Rprofile :
.R ou .Rmd.Rprofile et reproductibilitéLe .Rprofile est chargé dans l’environnement à chaque execution d’un processus R (Rscript et R).
.Rprofile (GitHub)--vanilla - pour désactiver le chargement de tous les fichiers de démarrage
--no-init-file - pour désactiver le chargement du fichier .Rprofile
--no-environ - pour désactiver le chargement du fichier .Renviron
If the first line of your R script is
setwd("C:\Users\jenny\path\that\only\I\have")I will come into your office and SET YOUR COMPUTER ON FIRE 🔥.
— Jenny Bryan
setwd() ! setwd() !library(ggplot2)
setwd("/path/to/a/directory/on/my/laptop/data")
df <- read.delim("data.csv")
p <- ggplot(df, aes(x, y)) + geom_point()
ggsave("../figs/scatterplot.png")
setwd() !library(ggplot2)
setwd("/path/to/a/directory/on/my/laptop/data")
df <- read.delim("data.csv")
p <- ggplot(df, aes(x, y)) + geom_point()
setwd("/path/to/a/directory/on/my/laptop/figs")
ggsave("scatterplot.png")
setwd() !here“What They Forgot to Teach You About R” — Jenny Bryan & Jim Hester
“Project-oriented Workflow” — Jenny Bryan
“Code Smells and Feels” — Jenny Bryan
“Advanced R” — Hadley Wickham
“Project-oriented Workflow” — Jenny Bryan
“R for Data Science” — Garrett Grolemund & Hadley Wickham
“What They Forgot to Teach You About R” — Jenny Bryan & Jim Hester